package com.app.mapper;

import com.app.model.Fwjz;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 房屋交租记录 Mapper 接口
 * </p>
 *
 * @author yoominic
 * @since 2025-02-27
 */
public interface FwjzMapper extends BaseMapper<Fwjz> {


    @Select("SELECT *\n" +
            "FROM fwjz\n" +
            "WHERE 1 = 1 \n" +
            "  AND unique_id = #{uniqueId} \n" +
            "  AND (pay_time BETWEEN DATE_SUB(DATE_SUB(CURDATE(), INTERVAL DAY(CURDATE()) - 1 DAY), INTERVAL 1 MONTH) AND LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) \n" +
            "       OR until_pay_time BETWEEN DATE_SUB(DATE_SUB(CURDATE(), INTERVAL DAY(CURDATE()) - 1 DAY), INTERVAL 1 MONTH) AND LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) \n" +
            "       OR (pay_time <= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL DAY(CURDATE()) - 1 DAY), INTERVAL 1 MONTH) AND until_pay_time >= LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))))")
    List<Fwjz> selectCurrentLogByUniqueId(@Param("uniqueId") String uniqueId);

}
